﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace CMSLibrary.TagsCreate.CustomFunction
{
    public abstract class PFunctionBase : PublicMethod
    {
        #region 成员        
        /// <summary>
        /// 分隔参数的符号
        /// </summary>
        protected char SplitParametersChar = ',';
        /// <summary>
        /// 重载索引
        /// </summary>
        public enum BurdenIndex
        {
            one, two, three, four, five, six, seven, eight, nine
        }
        /// <summary>
        /// 获取或设置重载索引
        /// </summary>
        public BurdenIndex FunctionBurden = BurdenIndex.one;        
        /// <summary>
        /// 截取的数组
        /// </summary>
        public string[] params_values;
        /// <summary>
        /// 当前栏目编号
        /// </summary>
        protected int currentClassID = 0;
        /// <summary>
        /// 要从其它的栏目为起始点的标识
        /// </summary>
        protected string otherword = "other";        
        #endregion

        #region 属性
        /// <summary>
        /// 当前栏目编号
        /// </summary>
        public int CurrentClassID
        {
            set { currentClassID = value; }
        }
        /// <summary>
        /// 参数源字符串
        /// </summary>
        public string ParametersSource
        {
            set
            {                
                SplitFormatParas(value);
            }
        }
        #endregion

        #region 公开方法
        /// <summary>
        /// 处理参数，返回该类格式化信息的字符串
        /// </summary>        
        public override string ToString()
        {
            return this.GetType().ToString();
        }
        #endregion

        #region 私有方法
        /// <summary>
        /// 拆分参数成数组
        /// </summary>
        /// <param name="source">源参数文本</param>
        /// <returns>去空格的字符串数组</returns>
        protected string[] GetParasArray(string source)
        {
            string[] result = null;
            //参数为空，则退出
            if (source == string.Empty) { return result; }
            //拆分参数
            result = source.Split(SplitParametersChar);
            //去空格
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = result[i].Trim();
            }
            return result;
        }
        #endregion

        #region 抽象方法
        /// <summary>
        /// 拆分参数并换成指定的数据类型
        /// </summary>
        protected abstract void SplitFormatParas(string sourceParas);
        #endregion

        #region 共用方法
        /// <summary>
        /// 获取数组中指定索引下的数组
        /// </summary>
        /// <param name="source">源数组</param>
        /// <param name="startIndex">起始索引</param>
        /// <returns>截取的数组</returns>
        protected string[] GetValuesForStartIndex(string[] source, int startIndex)
        {
            string[] result = new string[source.Length - startIndex];
            int n = 0;
            for (int i = startIndex; i < source.Length; i++)
            {
                result[n] = source[i];
                n++;
            }
            return result;
        }
        /// <summary>
        /// 验证该参数是否是'other'
        /// </summary>
        /// <param name="tagkey"></param>
        protected void ExistOther(string tagkey)
        {
            if (otherword.ToLower() != tagkey.ToLower())
            {
                throw new Exception("other参数不对");
            }
        }
        #endregion

    }
}
